#include <QWidget>
#include <QUdpSocket>
#include <QAudioInput>
#include <QAudioOutput>
#include <QPushButton>
#include <QLineEdit>

class VoiceClient : public QWidget {
    Q_OBJECT
public:
    VoiceClient(QWidget *parent = nullptr);

public slots:
    void toggleCall();
    void readPendingDatagrams();
    void handleStateChanged(QAudio::State state);

private:
    QUdpSocket *udpSocket;
    QAudioInput *audioInput;
    QAudioOutput *audioOutput;
    QIODevice *inputDevice;
    QIODevice *outputDevice;
    QAudioFormat format;

    QPushButton *callButton;
    QLineEdit *serverIPEdit;
    QLineEdit *serverPortEdit;
    bool isCalling;

    void initAudio();
    void startCall();
    void stopCall();
};
